home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Textdisplayers / MoreIsBetter / fenestrate.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  3KB  |  108 lines

  1. /* by Paul Kienitz, 5/18/89.  Public domain. */
  2.  
  3. #include <Paul.h>
  4.  
  5. main()
  6. {
  7.     char where[256], oldspec[256];
  8.     FILE *m;
  9.     bool FindCON();
  10.     void DOIT();
  11.  
  12.     puts("\nThis program will surgically replace the CON: window spec in a");
  13.     puts("copy of the MORE program that came with your Amiga.  See the file");
  14.     puts("\"Fenestrate.readme\" for hints on what sort of changes to make.");
  15.     puts("\nFirst I need the pathname of the copy of More to work on,");
  16.     puts("like maybe SYS:Utilities/More or C:More.");
  17.     for (;;) {
  18.     put("\nWhere is it?  [return to quit]  ");
  19.     if (!gets(where) || !strlen(where)) {
  20.         puts("\nOkay, forget it.");
  21.         Delay(30L);
  22.         exit(5);
  23.     }
  24.     if (m = fopen(where, "r+")) {
  25.         if (FindCON(m, oldspec))
  26.         DOIT(oldspec, m);
  27.         else
  28.         puts("\nCouldn't find a window spec in that file.");
  29.         fclose(m);
  30.     } else
  31.         puts("\nCouldn't find anything there.");
  32.     }
  33. }
  34.  
  35.  
  36.  
  37. bool FindCON(m, oldspec) FILE *m; str oldspec;
  38. {
  39.     int c;
  40.     long p;
  41.  
  42.     for (;;) {
  43.     do c = getc(m); while (c != EOF && toupper(c) != 'C');
  44.     if (feof(m)) return (false);
  45.     if (ferror(m)) {
  46.         puts("\nGaah!  Read error in trying to search the file!");
  47.         return (false);
  48.     }
  49.     if (toupper(getc(m)) == 'O' && toupper(getc(m)) == 'N' &&
  50.             getc(m) == ':' && getc(m) > ' ') {
  51.         fseek(m, -5L, 1);  /* back up to beginning of CON:... */
  52.         p = ftell(m);
  53.         c = fread(oldspec, 1, 255, m);
  54.         oldspec[255] = 0;
  55.         if (!c) {
  56.         puts("\nGaah!  Read error in trying to search the file!");
  57.         return (false);
  58.         }
  59.         if (strlen(oldspec) > 250) {
  60.         puts("\n**** Something's wrong; the window spec string is");
  61.         puts("**** too long!  Proceed at your own risk!");
  62.         }
  63.         fseek(m, p, 0);   /* position for rewriting */
  64.         return (true);
  65.     }
  66.     }
  67. }
  68.  
  69.  
  70.  
  71. void DOIT(oldspec, m) str oldspec; FILE *m;
  72. {
  73.     char spec[256];
  74.     int l, ll, g;
  75.  
  76.     for (;;) {
  77.     puts("The old window spec is as follows:");
  78.     put("   ");
  79.     puts(oldspec);
  80.     put("Your new specification?  [return to quit]  ");
  81.     if (gets(spec) && (l = strlen(spec)) > 3) {
  82.         if (l <= strlen(oldspec)) {
  83.         put("CONFIRM:  Your new spec is \"");
  84.         put(spec);
  85.         put("\".\nType Y to go ahead and put it in: ");
  86.         if ((g = toupper(getchar())) == 'Y') {
  87.             ll = fwrite(spec, 1, l + 1, m);
  88.             if (ll != l + 1) {
  89.             puts("\nGAAAH!  The write failed!");
  90.             if (ll) 
  91.                 puts("AND THE FILE IS PROBABLY CORRUPT NOW!");
  92.             else
  93.                 puts("I think the file is unchanged.");
  94.             } else puts("\nAll done.");
  95.             exit(0);
  96.         } else
  97.             puts("\nOkay, I'll let you retype it.");
  98.         while (g && g != '\n') g = getchar();
  99.         } else
  100.         puts("\nSorry, the new spec CANNOT be longer than the old one.");
  101.     } else {
  102.         puts("\nOkay, forget it.");
  103.         Delay(30L);
  104.         exit(5);
  105.     }
  106.     }
  107. }
  108.